//
//  ViewController.m
//  24-HomeWork
//
//  Created by dllo on 16/8/16.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *text1;
@property (weak, nonatomic) IBOutlet UITextField *text2;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}


- (IBAction)jieMi:(id)sender {

AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFJSONResponseSerializer serializer];
    NSString *parameters = [NSString stringWithFormat:@"secret=%@", _text2.text];
    [session.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        return parameters;
    }];
    [session POST:@"http://tool.zzblo.com/api/md5/decrypt" parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"解密成功");
        NSString *str = [responseObject objectForKey:@"text"];
        _text1.text = str;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        _text1.text = @"解密失败";
    }];

}
- (IBAction)zhuanHuan:(id)sender {
    
}
- (IBAction)addPassWord:(id)sender {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    NSString *parameters = [NSString stringWithFormat:@"text=%@",_text1.text];
    [manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        return parameters;
    }];
    [manager POST:@"http://tool.zzblo.com/api/md5/encrypt" parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"加密成功");
        NSString *string = [responseObject objectForKey:@"secret16"];
        _text2.text = string;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"加密失败");
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
